var get=require('../../utils/getRequest');
var post=require('../../utils/postRequest');
const api= require('../../utils/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
      buyOrderList:[],
      rentOrderList:[],
      active:0
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    var that=this;
    if(api.openId==null){
        wx.login({
          success: (res) => {
            var code=res.code;
            var data={code:code};
            get.getRequest(null,api.getOpenIdByCode,data).then(res=>{
              if (res.code == 200) {
                api.openId=res.data.openId;
                that.initOrder();
             }
            })
          },
        })
    }else{
      that.initOrder();
    }
  },
initOrder(){
  var that=this;
  wx.showLoading({
    title: '努力加载中',
  })
  var data={
    openId:api.openId
  }
  get.getRequest(null,api.getClientOrders,data).then(res=>{
      console.log(res);
        var orders=res.data;
        var buyOrderList=orders.filter(i=>i.buyType == 2 && i.payState == 3);
        var rentOrderList=orders.filter(i=>i.buyType == 1 && i.payState == 3);
        that.setData({
          buyOrderList:buyOrderList,
          rentOrderList:rentOrderList
        })
  }).finally(res=>{
    wx.hideLoading();
  })
},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})